//
//  LoginView.m
//  SUZHOUBANK
//
//  Created by saberLily on 16/4/11.
//  Copyright © 2016年 RuiFeng-WGCC. All rights reserved.
//

#import "LoginView.h"
#import "DefineHeader.h"
#import "TextLogin.h"
@implementation LoginView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.frame = frame;
        self.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.backImage];
        [self addSubview:self.backImageLeft];
        [self addSubview:self.backImageRight];
        [self addSubview:self.backImageTop];
        [self addSubview:self.backImageLogo];
        [self.backImageLogo addSubview:self.backImageLoad];
        TextLogin *login = [[TextLogin alloc]initWithFrame:CGRectMake(self.bounds.size.width / 2 + 20, self.bounds.size.height / 3, self.bounds.size.width / 16 * 7, self.bounds.size.height / 5 )];
        
        [self addSubview:login];
        [self positionAnimation];
    }
    return self;
}

- (UIImageView *)backImage{
    if (!_backImage) {
        _backImage = [[UIImageView alloc]initWithFrame:self.frame];
        _backImage.image = [UIImage imageNamed:@"登录_背景"];
    }
    return _backImage;
}

- (UIImageView *)backImageLeft{
    if (!_backImageLeft) {
        _backImageLeft = [[UIImageView alloc]initWithFrame:self.frame];
        _backImageLeft.image = [UIImage imageNamed:@"左"];
    }
    return _backImageLeft;
}

- (UIImageView *)backImageRight{
    if (!_backImageRight) {
        _backImageRight = [[UIImageView alloc]initWithFrame:self.frame];
        _backImageRight.image = [UIImage imageNamed:@"右"];
    }
    return _backImageRight;
}

- (UIImageView *)backImageTop{
    if (!_backImageTop) {
        _backImageTop = [[UIImageView alloc]initWithFrame:self.frame];
        _backImageTop.image = [UIImage imageNamed:@"上"];
    }
    return _backImageTop;
}

- (UIImageView *)backImageLogo{
    if (!_backImageLogo) {
//        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(respondForTap)];
        _backImageLogo = [[UIImageView alloc]initWithFrame:self.frame];
        _backImageLogo.image = [UIImage imageNamed:@"登录_logo"];
//        [_backImageLogo addGestureRecognizer:tap];
        _backImageLogo.userInteractionEnabled =YES;
    }
    return _backImageLogo;
}

- (UIImageView *)backImageLoad{
    if (!_backImageLoad) {
        _backImageLoad = [[UIImageView alloc]initWithFrame:CGRectMake(self.bounds.size.width * 0.63, self.bounds.size.height * 0.398, self.bounds.size.width / 4, 10)];
        _backImageLoad.image = [UIImage imageNamed:@"load"];
    }
    return _backImageLoad;
}

- (void)positionAnimation{
    [UIView animateWithDuration:10.0f animations:^{
        [UIView setAnimationCurve:UIViewAnimationCurveLinear];
//        [UIView setAnimationRepeatAutoreverses:YES];
        _backImageTop.center = CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 3);
        _backImageRight.center = CGPointMake(self.bounds.size.width / 3, self.bounds.size.height / 2);
        _backImageLeft.center = CGPointMake(self.bounds.size.width / 3 * 2, self.bounds.size.height / 2);
    }completion:^(BOOL finished) {
        [self rePositionAnimation];
    }];
}

- (void)rePositionAnimation{
    [UIView animateWithDuration:10.0f animations:^{
        [UIView setAnimationCurve:UIViewAnimationCurveLinear];
        _backImageTop.center = CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2);
        _backImageLeft.center = CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2);
        _backImageRight.center = CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2);
    }completion:^(BOOL finished) {
        [self positionAnimation];
    }];
}


@end
